package com.ruoyi.web.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.SoftwareVersion;
import com.ruoyi.web.service.ISoftwareVersionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 软件版本Controller
 * 
 * @author song
 * @date 2024-08-26
 */
@RestController
@RequestMapping("/software/version")
public class SoftwareVersionController extends BaseController
{
    @Autowired
    private ISoftwareVersionService softwareVersionService;

    /**
     * 查询软件版本列表
     */
    @PreAuthorize("@ss.hasPermi('software:version:list')")
    @GetMapping("/list")
    public TableDataInfo list(SoftwareVersion softwareVersion)
    {
        startPage();
        List<SoftwareVersion> list = softwareVersionService.selectSoftwareVersionList(softwareVersion);
        return getDataTable(list);
    }

    /**
     * 导出软件版本列表
     */
    @PreAuthorize("@ss.hasPermi('software:version:export')")
    @Log(title = "软件版本", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SoftwareVersion softwareVersion)
    {
        List<SoftwareVersion> list = softwareVersionService.selectSoftwareVersionList(softwareVersion);
        ExcelUtil<SoftwareVersion> util = new ExcelUtil<SoftwareVersion>(SoftwareVersion.class);
        util.exportExcel(response, list, "软件版本数据");
    }

    /**
     * 获取软件版本详细信息
     */
    @PreAuthorize("@ss.hasPermi('software:version:query')")
    @GetMapping(value = "/{versionId}")
    public AjaxResult getInfo(@PathVariable("versionId") Long versionId)
    {
        return success(softwareVersionService.selectSoftwareVersionByVersionId(versionId));
    }

    /**
     * 新增软件版本
     */
    @PreAuthorize("@ss.hasPermi('software:version:add')")
    @Log(title = "软件版本", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SoftwareVersion softwareVersion)
    {
        return toAjax(softwareVersionService.insertSoftwareVersion(softwareVersion));
    }

    /**
     * 修改软件版本
     */
    @PreAuthorize("@ss.hasPermi('software:version:edit')")
    @Log(title = "软件版本", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SoftwareVersion softwareVersion)
    {
        return toAjax(softwareVersionService.updateSoftwareVersion(softwareVersion));
    }

    /**
     * 删除软件版本
     */
    @PreAuthorize("@ss.hasPermi('software:version:remove')")
    @Log(title = "软件版本", businessType = BusinessType.DELETE)
	@DeleteMapping("/{versionIds}")
    public AjaxResult remove(@PathVariable Long[] versionIds)
    {
        return toAjax(softwareVersionService.deleteSoftwareVersionByVersionIds(versionIds));
    }
}
